package com.neusoft.acquistion.sensor.consumer.cfg;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.function.client.WebClient;

@Configuration
public class RestTemplateConfig {

    @Value("${application.config.base-url}")
    private String addressBaseUrl;
    @Bean
    public RestTemplate restTemplate( ) {
        return new RestTemplate( );
    }
//
//    WebClient webClient = WebClient.create();
//
//    Mono<String> mono = webClient
//            .get() // GET 请求
//            .uri("http://jsonplaceholder.typicode.com/posts/1")  // 请求路径
//            .retrieve() // 获取响应体
//            .bodyToMono(String.class); //响应数据类型转换
//
//System.out.println(mono.block());
//
//    WebClient webClient = WebClient.create("http://jsonplaceholder.typicode.com");
//
//    Mono<String> mono = webClient
//            .get() // GET 请求
//            .uri("/posts/1")  // 请求路径
//            .retrieve() // 获取响应体
//            .bodyToMono(String.class); //响应数据类型转换
//
//System.out.println(mono.block());




    @Bean
    public WebClient webClient() {
        return WebClient.builder()
                .baseUrl("http://127.0.0.1:8010")
                .defaultHeader(HttpHeaders.USER_AGENT,"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)")
                .defaultCookie("ACCESS_TOKEN", "test_token")
                .build();
//        return WebClient.builder().baseUrl(addressBaseUrl).build();
    }


//    @Bean
//    public AsyncRestTemplate asyncRestTemplate() {
//        return new AsyncRestTemplate();
//    }
}
